package com.ep.util;

import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.ep.demo.entity.Book;
import com.ep.entity.Paper;
import com.ep.factory.BeanFactory;
import com.ep.parse.IBaseParse;



public class CNKISearch implements IBaseSearch {

	@Override
	public List<Paper> search() {
		IBaseParse ibp=null;
		List<Paper> papers=null;
		//TODO 可优化
		ibp=(IBaseParse) BeanFactory.newInstanceBean("com.ep.parse.CNKIParse");
		HttpClient hc=new DefaultHttpClient(); 
		HttpGet hg = new HttpGet(
				"http://s.etao.com/search?q=i5-4590");
//		HttpGet hg = new HttpGet(
//				"http://epub.cnki.net/kns/brief/brief.aspx?pagename=ASP.brief_default_result_aspx&dbPrefix=SCDB&dbCatalog=%E4%B8%AD%E5%9B%BD%E5%AD%A6%E6%9C%AF%E6%96%87%E7%8C%AE%E7%BD%91%E7%BB%9C%E5%87%BA%E7%89%88%E6%80%BB%E5%BA%93&ConfigFile=SCDBINDEX.xml&research=off&t=1456329203972&keyValue=%E6%B2%B3%E5%8C%97%E7%A7%91%E6%8A%80%E5%A4%A7%E5%AD%A6&S=1");
		HttpResponse response=null;
		try {
			response = hc.execute(hg);
			HttpEntity entity = response.getEntity();
			System.out.println(new String(EntityUtils.toString(entity).getBytes(), "GBK") );
			papers = ibp.parseHtml(entity.getContent());
			EntityUtils.consume(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return papers;
	}

}
